<?xml version="1.0"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html><head><title>SASAPI</title><script src="../../../quicknav.js" type="text/javascript"></script><script><!--
document.quicknavBasePath="../../../index-files";
//--></script><link href="../../../style.css" title="JavaDoc" rel="stylesheet" type="text/css"/><link href="../../../unnatural.css" title="Unnatural" rel="alternate stylesheet" type="text/css"/><link href="../../../overview-summary.html" title="Overview" rel="top"/><meta name="generator" content="http://www.badgers-in-foil.co.uk/projects/as2api/"/></head><body><pre><span class="lineno" id="1">     1  </span><span class="comment doc">/**
<span class="lineno" id="2">     2  </span> * properties.CurveModifiers
<span class="lineno" id="3">     3  </span> * List of default special properties modifiers for the Tweener class
<span class="lineno" id="4">     4  </span> * The function names are strange/inverted because it makes for easier debugging (alphabetic order). They're only for internal use (on this class) anyways.
<span class="lineno" id="5">     5  </span> *
<span class="lineno" id="6">     6  </span> * @author		Zeh Fernando, Nate Chatellier, Arthur Debert
<span class="lineno" id="7">     7  </span> * @version		1.0.0
<span class="lineno" id="8">     8  </span> */</span>
<span class="lineno" id="9">     9  </span>
<span class="lineno" id="10">    10  </span><span class="key">import</span> caurina.transitions.Tweener;
<span class="lineno" id="11">    11  </span>
<span class="lineno" id="12">    12  </span><span class="key">class</span> caurina.transitions.properties.CurveModifiers {
<span class="lineno" id="13">    13  </span>
<span class="lineno" id="14">    14  </span>	<span class="comment doc">/**
<span class="lineno" id="15">    15  </span>	 * There's no constructor.
<span class="lineno" id="16">    16  </span>	 */</span>
<span class="lineno" id="17">    17  </span>	<span class="key">public</span> <span class="key">function</span> CurveModifiers () {
<span class="lineno" id="18">    18  </span>		trace (<span class="str_const">"This is an static class and should not be instantiated."</span>)
<span class="lineno" id="19">    19  </span>	}
<span class="lineno" id="20">    20  </span>
<span class="lineno" id="21">    21  </span>	<span class="comment doc">/**
<span class="lineno" id="22">    22  </span>	 * Registers all the special properties to the Tweener class, so the Tweener knows what to do with them.
<span class="lineno" id="23">    23  </span>	 */</span>
<span class="lineno" id="24">    24  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> init():Void {
<span class="lineno" id="25">    25  </span>
<span class="lineno" id="26">    26  </span>		<span class="comment">// Bezier modifiers</span>
<span class="lineno" id="27">    27  </span>		Tweener.registerSpecialPropertyModifier(<span class="str_const">"_bezier"</span>, _bezier_modifier, _bezier_get);
<span class="lineno" id="28">    28  </span>	}
<span class="lineno" id="29">    29  </span>
<span class="lineno" id="30">    30  </span>
<span class="lineno" id="31">    31  </span>	<span class="comment">// ==================================================================================================================================</span>
<span class="lineno" id="32">    32  </span>	<span class="comment">// SPECIAL PROPERTY MODIFIER functions ----------------------------------------------------------------------------------------------</span>
<span class="lineno" id="33">    33  </span>
<span class="lineno" id="34">    34  </span>	<span class="comment">// ----------------------------------------------------------------------------------------------------------------------------------</span>
<span class="lineno" id="35">    35  </span>	<span class="comment">// _bezier</span>
<span class="lineno" id="36">    36  </span>
<span class="lineno" id="37">    37  </span>	<span class="comment doc">/**
<span class="lineno" id="38">    38  </span>	 * Given the parameter object passed to this special property, return an array listing the properties that should be modified, and their parameters
<span class="lineno" id="39">    39  </span>	 *
<span class="lineno" id="40">    40  </span>	 * @param		p_obj				Object		Parameter passed to this property
<span class="lineno" id="41">    41  </span>	 * @return							Array		Array listing name and parameter of each property
<span class="lineno" id="42">    42  </span>	 */</span>
<span class="lineno" id="43">    43  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> _bezier_modifier (p_obj:Object):Array {
<span class="lineno" id="44">    44  </span>		<span class="key">var</span> mList:Array = []; <span class="comment">// List of properties to be modified</span>
<span class="lineno" id="45">    45  </span>		<span class="key">var</span> pList:Array; <span class="comment">// List of parameters passed, normalized as an array</span>
<span class="lineno" id="46">    46  </span>		<span class="key">if</span> (p_obj <span class="key">instanceof</span> Array) {
<span class="lineno" id="47">    47  </span>			<span class="comment">// Complex</span>
<span class="lineno" id="48">    48  </span>			pList = p_obj.concat();
<span class="lineno" id="49">    49  </span>		} <span class="key">else</span> {
<span class="lineno" id="50">    50  </span>			pList = [p_obj];
<span class="lineno" id="51">    51  </span>		}
<span class="lineno" id="52">    52  </span>
<span class="lineno" id="53">    53  </span>		<span class="key">var</span> i:Number;
<span class="lineno" id="54">    54  </span>		<span class="key">var</span> istr:String;
<span class="lineno" id="55">    55  </span>		<span class="key">var</span> mListObj:Object = {}; <span class="comment">// Object describing each property name and parameter</span>
<span class="lineno" id="56">    56  </span>
<span class="lineno" id="57">    57  </span>		<span class="key">for</span> (i = <span class="num_const">0</span>; i &lt; pList.length; i++) {
<span class="lineno" id="58">    58  </span>			<span class="key">for</span> (istr <span class="key">in</span> pList[i]) {
<span class="lineno" id="59">    59  </span>				<span class="key">if</span> (mListObj[istr] == undefined) mListObj[istr] = [];
<span class="lineno" id="60">    60  </span>				mListObj[istr].push(pList[i][istr]);
<span class="lineno" id="61">    61  </span>			}
<span class="lineno" id="62">    62  </span>		}
<span class="lineno" id="63">    63  </span>		<span class="key">for</span> (istr <span class="key">in</span> mListObj) {
<span class="lineno" id="64">    64  </span>			mList.push({name:istr, parameters:mListObj[istr]});
<span class="lineno" id="65">    65  </span>		}
<span class="lineno" id="66">    66  </span>		<span class="key">return</span> mList;
<span class="lineno" id="67">    67  </span>	}
<span class="lineno" id="68">    68  </span>
<span class="lineno" id="69">    69  </span>	<span class="comment doc">/**
<span class="lineno" id="70">    70  </span>	 * Given tweening specifications (beging, end, t), applies the property parameter to it, returning new t
<span class="lineno" id="71">    71  </span>	 *
<span class="lineno" id="72">    72  </span>	 * @param		b					Number		Beginning value of the property
<span class="lineno" id="73">    73  </span>	 * @param		e					Number		Ending (desired) value of the property
<span class="lineno" id="74">    74  </span>	 * @param		t					Number		Current t of this tweening (0-1), after applying the easing equation
<span class="lineno" id="75">    75  </span>	 * @param		p					Array		Array of parameters passed to this specific property
<span class="lineno" id="76">    76  </span>	 * @return							Number		New t, with the p parameters applied to it
<span class="lineno" id="77">    77  </span>	 */</span>
<span class="lineno" id="78">    78  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> _bezier_get (b:Number, e:Number, t:Number, p:Array):Number {
<span class="lineno" id="79">    79  </span>		<span class="comment">// This is based on Robert Penner's code</span>
<span class="lineno" id="80">    80  </span>		<span class="key">if</span> (p.length == <span class="num_const">1</span>) {
<span class="lineno" id="81">    81  </span>			<span class="comment">// Simple curve with just one bezier control point</span>
<span class="lineno" id="82">    82  </span>			<span class="key">return</span> b + t*(<span class="num_const">2</span>*(<span class="num_const">1</span>-t)*(p[<span class="num_const">0</span>]-b) + t*(e - b));
<span class="lineno" id="83">    83  </span>		} <span class="key">else</span> {
<span class="lineno" id="84">    84  </span>			<span class="comment">// Array of bezier control points, must find the point between each pair of bezier points</span>
<span class="lineno" id="85">    85  </span>			<span class="key">var</span> ip:Number = Math.floor(t * p.length); <span class="comment">// Position on the bezier list</span>
<span class="lineno" id="86">    86  </span>			<span class="key">var</span> it:Number = (t - (ip * (<span class="num_const">1</span> / p.length))) * p.length; <span class="comment">// t inside this ip</span>
<span class="lineno" id="87">    87  </span>			<span class="key">var</span> p1:Number, p2:Number;
<span class="lineno" id="88">    88  </span>			<span class="key">if</span> (ip == <span class="num_const">0</span>) {
<span class="lineno" id="89">    89  </span>				<span class="comment">// First part: belongs to the first control point, find second midpoint</span>
<span class="lineno" id="90">    90  </span>				p1 = b;
<span class="lineno" id="91">    91  </span>				p2 = (p[<span class="num_const">0</span>]+p[<span class="num_const">1</span>])/<span class="num_const">2</span>;
<span class="lineno" id="92">    92  </span>			} <span class="key">else</span> <span class="key">if</span> (ip == p.length - <span class="num_const">1</span>) {
<span class="lineno" id="93">    93  </span>				<span class="comment">// Last part: belongs to the last control point, find first midpoint</span>
<span class="lineno" id="94">    94  </span>				p1 = (p[ip-<span class="num_const">1</span>]+p[ip])/<span class="num_const">2</span>;
<span class="lineno" id="95">    95  </span>				p2 = e;
<span class="lineno" id="96">    96  </span>			} <span class="key">else</span> {
<span class="lineno" id="97">    97  </span>				<span class="comment">// Any middle part: find both midpoints</span>
<span class="lineno" id="98">    98  </span>				p1 = (p[ip-<span class="num_const">1</span>]+p[ip])/<span class="num_const">2</span>;
<span class="lineno" id="99">    99  </span>				p2 = (p[ip]+p[ip+<span class="num_const">1</span>])/<span class="num_const">2</span>;
<span class="lineno" id="100">   100  </span>			}
<span class="lineno" id="101">   101  </span>			<span class="key">return</span> p1+it*(<span class="num_const">2</span>*(<span class="num_const">1</span>-it)*(p[ip]-p1) + it*(p2 - p1));
<span class="lineno" id="102">   102  </span>		}
<span class="lineno" id="103">   103  </span>	}
<span class="lineno" id="104">   104  </span>}
<span class="lineno" id="105">   105  </span></pre><ul class="main_nav" id="main_nav"><li><a href="../../../overview-summary.html" title="Overview of SASAPI" class="button">Overview</a></li><li><a href="package-summary.html" title="Overview of package caurina.transitions.properties" class="button">Package</a></li><li><a href="CurveModifiers.html" title="Detail of caurina.transitions.properties.CurveModifiers API" class="button">Class</a></li><li><span class="button nav_current">Source</span></li><li><a href="../../../index-files/index.html" title="Alpabetical index of types and members" class="button">Index</a></li></ul><div class="footer"><a href="http://www.badgers-in-foil.co.uk/projects/as2api/" title="ActionScript 2 API Documentation Generator">as2api</a></div></body></html>